//
//  AdvantageTableViewCell.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/12.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "AdvantageTableViewCell.h"
#import "GLGWTagsView.h"

@implementation AdvantageTableViewCell
{
    GLGWLabel *titLabel;
    GLGWLabel *desLabel;
    GLGWTagsView *tageView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        GLGWLabel *titLa = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(16) theColor:kColor_Rule_Black inSuperView:self.contentView];
        [titLa mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.left.equalTo(self.contentView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(self.contentView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(20));
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(55));
        }];
        titLa.text = @"店铺优势";
        titLa.numberOfLines = 0;
        titLabel = titLa;
        
        GLGWLabel *desLab = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self];
        [desLab mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self->titLabel.mas_left);
            make.top.equalTo(self->titLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(15));
        }];
        desLab.text = @"暂无店铺优势";
        desLabel = desLab;
    }
    return self;
}

- (void)setModel:(StoreIntroduceModel *)model
{
    _model = model;
    StoreIntroduceDataModel *dataModel = model.data;
    if (dataModel.shopAdvantages.count <= 0) {
        desLabel.hidden = NO;
        return;
    }
    desLabel.hidden = YES;
    if (tageView) {
        [tageView removeFromSuperview];
        tageView = nil;
    }
    NSMutableArray *newArr = [NSMutableArray array];
    for (int i = 0; i < dataModel.shopAdvantages.count; i ++) {
        StoreIntroduceDataShopAdvantagesModel *adModel = dataModel.shopAdvantages[i];
        [newArr addObject:adModel.name];
    }
    tageView = [[GLGWTagsView alloc] initWithFrame:CGRectMake(0, kY_With_View(titLabel, 15), KScreenWidth, 0) tagsArray:newArr config:[self tagView] tagBackImgStr:@""];
    CGFloat hei = [tageView heighttagsArray:newArr config:[self tagView]] + kHeightProportion_In_iPhoneTriploid(35);
    [titLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-hei);
    }];
    [self addSubview:tageView];
}

- (FFTagsViewConfig *)tagView
{
    FFTagsViewConfig *config = [[FFTagsViewConfig alloc] init];
    config.itemHeight = kHeightProportion_In_iPhoneTriploid(30);
    config.itemHerMargin = kWidthProportion_In_iPhoneTriploid(15);
    config.itemVerMargin = kHeightProportion_In_iPhoneTriploid(10);
    config.hasBorder = YES;
    config.itemContentEdgs = kWidthProportion_In_iPhoneTriploid(15);
    config.borderRadius = kHeightProportion_In_iPhoneTriploid(15);
    config.topBottomSpace = 0.1;
    config.fontSize = 14.0;
    config.isCanSelected = YES;
    config.isCanCancelSelected = NO;
    config.isMulti = YES;
    config.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    config.normalTitleColor = [UIColor colorWithHexString:@"#999999"];
    config.selectedTitleColor = [UIColor colorWithHexString:@"#999999"];
    config.selectedBgImage = [UIImage imageWithColor:[UIColor colorWithHexString:@"#F2F2F2"]];
    config.fontSize = 14;
    return config;
}

@end
